package com.yun.zf.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yun.zf.common.admin.domain.SysDictType;
import com.yun.zf.common.admin.dto.sys.SysDictTypesDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 字典表 数据层
 * 
 * @author ruoyi
 */
@Mapper
public interface SysDictTypeMapper extends BaseMapper<SysDictType>
{
    /**
     * 根据条件分页查询字典类型
     * 
     * @param dictType 字典类型信息
     * @return 字典类型集合信息
     */
    @Select("<script>" +
            " SELECT * from sys_dict_type d WHERE 1=1 " +
            "<if test='dictName!=null  '> and dict_name = #{dictName} </if>" +
            "<if test='status!=null '> and status = #{status} </if>" +
            "<if test='dictType!=null  '> and dict_type = #{dictType} </if>" +
            " ORDER BY update_time desc "+
            "</script>")
    public List<SysDictType> selectDictTypeList(String dictName,String status,String dictType);


    @Select("<script>" +
            " select  dict_name, dict_type " +
            " from sys_dict_type where status = 0 " +
            "</script>")
    public List<SysDictTypesDto> selectDictTypeAll();

    /**
     * 根据字典类型ID查询信息
     * 
     * @param dictId 字典类型ID
     * @return 字典类型
     */
    @Select("<script>" +
            " select dict_id, dict_name, dict_type, status, create_by, create_time, remark  " +
            " from sys_dict_type where dict_id = #{dictId}" +
            "</script>")
    public SysDictType selectDictTypeById(Long dictId);

    /**
     * 根据字典类型查询信息
     * 
     * @param dictType 字典类型
     * @return 字典类型
     */
    public SysDictType selectDictTypeByType(String dictType);

    /**
     * 通过字典ID删除字典信息
     * 
     * @param dictId 字典ID
     * @return 结果
     */
    public int deleteDictTypeById(Long dictId);

    /**
     * 批量删除字典类型信息
     *
     * @return 结果
     */
    @Select("<script> " +
            " delete from sys_dict_type where dict_type in " +
            " <foreach collection=\"types\" index=\"i\" open=\"(\" separator=\",\" close=\")\" item=\"type\"  >#{type}</foreach>" +
            "</script>")
    public void deleteDictByTypes( String[] types);

    /**
     * 新增字典类型信息
     * 
     * @param dictType 字典类型信息
     * @return 结果
     */
    public int insertDictType(SysDictType dictType);

    /**
     * 修改字典类型信息
     * 
     * @param dictType 字典类型信息
     * @return 结果
     */
    public int updateDictType(SysDictType dictType);

    /**
     * 校验字典类型称是否唯一
     * 
     * @param dictType 字典类型
     * @return 结果
     */
    @Select("<script>" +
            " select dict_id, dict_name, dict_type, status, create_by, create_time, remark  " +
            " from sys_dict_type where dict_type = #{dictType}" +
            "</script>")
    public SysDictType checkDictTypeUnique(String dictType);
}
